import 'dart:ffi';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class MinView extends StatefulWidget {
  MinView({Key? key}) : super(key: key);

  @override
  _MinViewState createState() => _MinViewState();
}

class _MinViewState extends State<MinView> {
//构建头部信息区域
  Widget buildHeaderSection() {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
      color: const Color(0xFF78B1C5),
      child: Row(
        children: [
          //头像区域
          ClipRRect(
            borderRadius: BorderRadius.circular(25),
            child: Image.asset(
              "assets/images/avatar_1.jpg",
              width: 50,
              height: 50,
              fit: BoxFit.cover,
            ),
          ),
          const SizedBox(
            width: 15,
          ),
          //用户名
          const Text(
            '用户名',
            style: TextStyle(
              color: Colors.white,
              fontSize: 18,
              fontWeight: FontWeight.bold,
            ),
          ),
          const Spacer(),
          //完善信息的按钮
          GestureDetector(
            onTap: () {
              //信息点击事件
            },
            child: const Row(
              children: [
                Text(
                  '完善信息',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 14,
                  ),
                ),
                Icon(
                  Icons.chevron_right,
                  color: Colors.white,
                  size: 20,
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  // 构建功能列表区域
  Widget buildFunctionList() {
    return Container(
      margin: const EdgeInsets.all(15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Column(
        children: [
          buildFunctionItem(
            icon: 'assets/images/house_profile_icon@2x.png',
            title: '我的房屋',
            onTap: () {
              // 我的房屋点击事件
            },
          ),
          const Divider(height: 1),
          buildFunctionItem(
            icon: 'assets/images/repair_profile_icon@2x.png',
            title: '我的报修',
            onTap: () {
              // 我的报修点击事件
            },
          ),
          const Divider(height: 1),
          buildFunctionItem(
            icon: 'assets/images/visitor_profile_icon@2x.png',
            title: '访客记录',
            onTap: () {
              // 访客记录点击事件
            },
          ),
        ],
      ),
    );
  }

  Widget buildFunctionItem(
      {required String icon,
      required String title,
      required VoidCallback onTap}) {
    return InkWell(
      onTap: onTap,
      child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 20),
        child: Row(
          children: [
            Image.asset(
              icon,
              width: 24,
              height: 24,
            ),
            const SizedBox(width: 15),
            Text(
              title,
              style: const TextStyle(fontSize: 16, color: Colors.black87),
            ),
            const Spacer(),
            const Icon(
              Icons.chevron_right,
              color: Colors.grey,
              size: 20,
            ),
          ],
        ),
      ),
    );
  }

  //构建标题区域
  Widget buildTitleSection() {
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 15),
      alignment: Alignment.center,
      color: const Color(0xFF78B1C5),
      child: const Text(
        "我的",
        style: TextStyle(
          color: Colors.white,
          fontSize: 20,
          fontWeight: FontWeight.bold,
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFF78B1C5),
      body: SafeArea(
        top: false,
        child: Column(
          children: [
            Container(
              width: double.infinity,
              padding: EdgeInsets.only(
                top: MediaQuery.of(context).padding.top + 10,
                bottom: 10,
              ),
              color: const Color(0xFF78B1C5),
              child: const Center(
                child: Text(
                  '我的',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
            buildHeaderSection(),
            buildFunctionList()
          ],
        ),
      ),
    );
  }
}
